package com.ruoyi.device.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.device.domain.DeviceMaintain;
import com.ruoyi.device.service.IDeviceMaintainService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备维护管理Controller
 * 
 * @author ruoyi
 * @date 2023-01-12
 */
@Controller
@RequestMapping("/device/maintain")
public class DeviceMaintainController extends BaseController
{
    private String prefix = "device/maintain";

    @Autowired
    private IDeviceMaintainService deviceMaintainService;

    @RequiresPermissions("device:maintain:view")
    @GetMapping()
    public String maintain()
    {
        return prefix + "/maintain";
    }

    /**
     * 查询设备维护管理列表
     */
    @RequiresPermissions("device:maintain:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DeviceMaintain deviceMaintain)
    {
        startPage();
        List<DeviceMaintain> list = deviceMaintainService.selectDeviceMaintainList(deviceMaintain);
        return getDataTable(list);
    }

    /**
     * 导出设备维护管理列表
     */
    @RequiresPermissions("device:maintain:export")
    @Log(title = "设备维护管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DeviceMaintain deviceMaintain)
    {
        List<DeviceMaintain> list = deviceMaintainService.selectDeviceMaintainList(deviceMaintain);
        ExcelUtil<DeviceMaintain> util = new ExcelUtil<DeviceMaintain>(DeviceMaintain.class);
        return util.exportExcel(list, "设备维护管理数据");
    }

    /**
     * 新增设备维护管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存设备维护管理
     */
    @RequiresPermissions("device:maintain:add")
    @Log(title = "设备维护管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DeviceMaintain deviceMaintain)
    {
        return toAjax(deviceMaintainService.insertDeviceMaintain(deviceMaintain));
    }

    /**
     * 修改设备维护管理
     */
    @RequiresPermissions("device:maintain:edit")
    @GetMapping("/edit/{deviceId}")
    public String edit(@PathVariable("deviceId") String deviceId, ModelMap mmap)
    {
        DeviceMaintain deviceMaintain = deviceMaintainService.selectDeviceMaintainByDeviceId(deviceId);
        mmap.put("deviceMaintain", deviceMaintain);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备维护管理
     */
    @RequiresPermissions("device:maintain:edit")
    @Log(title = "设备维护管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DeviceMaintain deviceMaintain)
    {
        return toAjax(deviceMaintainService.updateDeviceMaintain(deviceMaintain));
    }

    /**
     * 删除设备维护管理
     */
    @RequiresPermissions("device:maintain:remove")
    @Log(title = "设备维护管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(deviceMaintainService.deleteDeviceMaintainByDeviceIds(ids));
    }
}
